package com.study.spmongodb.wwj.thread.char05;

/**
 * @author MI
 * @version 1.0
 * @date 2020/12/6 10:18
 */
public class ThreadJoin3 {
    public static void main(String[] args) throws InterruptedException {
        final long start = System.currentTimeMillis();

        Thread t1 = new Thread(new CaptureRunnable("M1", 10_000));
        Thread t2 = new Thread(new CaptureRunnable("M2", 20_000));
        Thread t3 = new Thread(new CaptureRunnable("M3", 10_000));

        t1.start();
        t2.start();
        t3.start();
        t1.join();
        t2.join();
        t3.join();
        final long endTime = System.currentTimeMillis();

        System.out.println(endTime - start);


    }


}

class CaptureRunnable implements Runnable {
    private String machineName;

    private long spendTime;

    public CaptureRunnable(String machineName, long spendTime) {
        this.machineName = machineName;
        this.spendTime = spendTime;
    }

    @Override
    public void run() {
        try {
            Thread.sleep(spendTime);
            System.out.println(machineName + " completed data ");
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }

    public String getResult() {
        return machineName + " finish.";
    }
}
